package cn.sytton.taffe.framework.util;

import cn.hutool.core.io.IoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

/**
 * 自定义启动Banner
 *
 * @author skyrock
 */
@Slf4j
@Component
public class Banner implements CommandLineRunner {

    @Value("${spring.application.name:}")
    private String name;
    @Value("${spring.application.version:}")
    private String version;

    @Override
    public void run(String... args) throws Exception {
        Resource resource = new ClassPathResource("banner");
        if (resource.exists()) {
            String text = IoUtil.readUtf8(resource.getInputStream());
            text = text.replace("${spring.application.name}", name).replace("${spring.application.version}", version);
            log.info("\n\n"+text+"\n");
        }
    }
}
